import Actions from './actions';
import DB from '../../app/db';
import {Toast} from 'saltui';
import Reflux from 'reflux';
import nattyStorage from 'natty-storage';

const {fromJS} = require('immutable');

const storageUser = nattyStorage({
  type: 'localStorage',
  key: 'sskj-dingtalk-user',
});


module.exports = Reflux.createStore({
  listenables: [Actions],
  data: {
    user: fromJS(storageUser),
    items: [],
  },

  onFetchList: function () {
    let t = this;

    DB.message.list({
      userId: t.data.user.get('userid'),
    }).then(
      function (content) {
        console.log(content);
        t.data.items = content.result.blackboardList;
        t.updateComponent();

      }, function (error) {
        console.log(error);
      });

  },

  updateComponent: function () {
    this.trigger(this.data);
  },

  getInitialState: function () {
    return this.data;
  }
});
